package com.wu.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.wu.demo.common.domain.AjaxResult;
import com.wu.demo.common.domain.LoginUser;
import com.wu.demo.common.domain.request.UserInfo;
import com.wu.demo.common.utils.excel.ExcelUtil;
import com.wu.demo.entity.SysUser;
import com.wu.demo.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "SSO管理")
@RestController
@RequestMapping("sso")
public class SsoController extends BaseController {
    @Autowired
    private ISysUserService userService;
    @Resource
    private RedisTemplate redisTemplate;

    @ApiOperation(value = "登录")
    @PostMapping("login")
    public AjaxResult login() {
        LoginUser token = userService.login(5L);
        return AjaxResult.success("成功", token);
    }

    @ApiOperation(value = "参数验证")
    @PostMapping("testValid")
    public AjaxResult testValid(@Validated @RequestBody UserInfo userInfo) {
        return AjaxResult.success("", JSONObject.toJSONString(userInfo));
    }

    @GetMapping("/export")
    public void export(HttpServletResponse response) {
        List<SysUser> list = userService.list();
        ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);
        util.exportExcel(list, response, "用户数据");
    }




    
}


